<template>
  <div class='main-container'>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>人员管理</el-breadcrumb-item>
      <el-breadcrumb-item>离职管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card class="box-card">
      <el-row :gutter="30">
        <!-- 搜索 -->
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" @keyup.enter.native="getUserLeaveList" clearable @clear="getUserLeaveList">
            <el-button slot="append" icon="el-icon-search" @click="getUserLeaveList"></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table :data="leaveList" style="width: 100%" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="user" label="发起人" width='70' ></el-table-column>
        <el-table-column prop="workNumber" label="工号" ></el-table-column>
        <el-table-column prop="department" label="部门" ></el-table-column>
        <el-table-column prop="post" label="岗位" ></el-table-column>
        <el-table-column prop="leaveReason" label="离职原因" ></el-table-column>
        <el-table-column prop="createTime" label="申请时间">
          <template slot-scope='scope'>
            {{scope.row.createTime|dateFormat}}
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <el-tag
              :type="getStatus(scope.row.status).color"
              disable-transitions>{{getStatus(scope.row.status).text}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column  label="操作" width="130">
          <template slot-scope="scope">
            <el-button type="success" size="mini" icon="el-icon-check" circle @click="removeById(scope.row)"></el-button>
            <el-button type="danger" size="mini" icon="el-icon-close" circle @click="removeById(scope.row)"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <!--    <el-pagination-->
      <!--        @size-change="handleSizeChange"-->
      <!--        @current-change="handleCurrentChange"-->
      <!--        :current-page="queryInfo.pagenum"-->
      <!--        :page-sizes="[1, 2, 5, 10]"-->
      <!--        :page-size="queryInfo.pageSize"-->
      <!--        layout="total, sizes, prev, pager, next, jumper"-->
      <!--        :total="total">-->
      <!--      </el-pagination>-->
    </el-card>
  </div>
</template>
<script>
  export default {
    data(){
      return {
        queryInfo:{
          query:'',
          pagenum:1,
          pagesize:10
        },
        leaveList:[],
        total:0
      }
    },
    async created() {
      await this.getUserLeaveList()
    },
    methods:{
      getUserLeaveList:async function(){
        // const {data:res}=await this.$http.get('shop/findAllcomm',)
        //   if(res.data.status!==200){
        //   return this.$message.error("获取失败")
        // }
        this.$message.success("获取离职请求列表成功")
        // this.contractsList=res.meta
        this.leaveList=[
          {
            leaveId:1,
            user:'李小龙',
            workNumber:'10005',
            department:'产品部',
            post:'产品经理',
            leaveReason:'升学',
            status:'0',
            createTime:'2022-04-18 00:00:00'
          }
        ]
      },
      getStatus(val){
        let statusMap = {
          '0':{color:'warning',text:'待审批'},
          '1':{color:'success',text:'已审批'},
          '2':{color:'danger',text:'已驳回'},
        }
        return statusMap[val]
      },
      // 获取最新的pagesize
      handleSizeChange:function(newsize){
        this.queryInfo.pagesize=newsize
        this.getUserLeaveList()
      },
      handleCurrentChange:function(newPage){
        this.queryInfo.pagenum=newPage
        this.getUserLeaveList()
      },
      removeById:async function(id){
        // 确认对话框
        const confirmResult=await this.$confirm("此操作将永久删除,是否继续?",'删除商品',{
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).catch(err=>err)
        if(confirmResult!=='confirm'){
          return this.$message.info('已取消')
        }
        const {data:res}=await this.$http.delete(`goods/${id}`)
        console.log(res)
        if(res.data.status!==200){
          return this.$message.error("删除失败")
        }
        this.$message.success("删除成功")
        this.getUserLeaveList()
      },
      addToCar:async function(good) {
        console.log(good,'good')
        const { data: res } = await this.$http.get(`shop/addCommToCar?commNames=${good.name}&uid=${good.commId}`)
        console.log(res)
        if (res.data.status !== 200) {
          return this.$message.error("购买失败")
        }
        this.$message.success("购买成功!!")
      }
    }
  }
</script>
<style lang="less">
  .main-container{
    padding: 10px 20px;
    h4{
      color: gray;
      font-size:20px;
      font-weight: normal
    }
  }
</style>
